package com.hxkj.controller.taglib;

import com.hxkj.domain.po.FreeMarker;
import com.hxkj.client.service.taglib.BreadcrumbsTagService;
import com.integral.mall.file.po.SysFile;
import com.platform.common.domain.exception.CustomException;
import com.platform.common.domain.exception.CustomMessageException;
import com.platform.common.domain.result.ResultDataStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * 自定标标签--面包屑
 * <p>
 * Created by chenfangzhou on 2018年7月18日13:49:56
 */
@RestController
@RequestMapping("/tags")
public class BreadcrumbsController {

    @Autowired
    private BreadcrumbsTagService breadcrumbsTagService;

    /**
     * 静态模板解析
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/breadcrumbs", method = RequestMethod.POST,consumes = "application/json;charset=UTF-8")
    public Callable<ResultDataStruct<SysFile>> getBreadcrumbsTag(@RequestBody FreeMarker freeMarker) throws Exception {
        return ()-> {
            ResultDataStruct<SysFile> resultDataStruct = new ResultDataStruct<>();
            try {
                SysFile sysFile = breadcrumbsTagService.getBreadcrumbsTag(freeMarker);
                resultDataStruct.setData(sysFile);
                resultDataStruct.setCode(200);
                resultDataStruct.setMessage("成功");
            }catch (CustomException e){
                resultDataStruct.setCode(e.getCode().getCode());
                resultDataStruct.setMessage(e.getMessage());
            }catch (CustomMessageException e){
                resultDataStruct.setCode(e.getCode());
                resultDataStruct.setMessage(e.getMessage());
            }
            return resultDataStruct;
        };
    }

}
